package com.work.straighttalk.ui;

import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.work.straighttalk.R;
import com.work.straighttalk.adapter.OnSearchListener;
import com.work.straighttalk.adapter.SearchUserAdapter;
import com.work.straighttalk.app.BaseActivity;
import com.work.straighttalk.bean.User;
import com.work.straighttalk.presenter.SearchUserPImpl;
import com.work.straighttalk.presenter.i.SearchUserPI;
import com.work.straighttalk.ui.i.SearchUserVI;

import java.util.List;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * 查询用户页面
 * Created by 肖江宏 on 16/3/4.
 */
public class SearchUserActivity extends BaseActivity implements SearchUserVI, OnSearchListener {

    @Bind(R.id.et_find_name)
    EditText etFindName;
    @Bind(R.id.btn_search)
    Button btnSearch;
    @Bind(R.id.rc_view)
    RecyclerView rcView;
    @Bind(R.id.sw_refresh)
    SwipeRefreshLayout swRefresh;

    private SearchUserAdapter adp;
    private SearchUserPI searchUserPI;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_seacher_user);

        searchUserPI = new SearchUserPImpl(this);
        rcView.setLayoutManager(new GridLayoutManager(this, 1));
        adp = new SearchUserAdapter(this);
        rcView.setAdapter(adp);

    }

    @OnClick(R.id.btn_search)
    public void onSearchClick(View view) {
        swRefresh.setRefreshing(true);
        searchUserPI.validateUserGetList(etFindName.getText().toString());
    }

    @Override
    public void addFrends() {
        toast("发送请求成功,等待用户添加");
    }

    @Override
    public void userNUll() {
        toast("请填写用户名");
        swRefresh.setRefreshing(false);
    }


    @Override
    public void UserError(int i, String s) {
        swRefresh.setRefreshing(false);
        toast(s + "(" + i + ")");
    }

    @Override
    public void showItem(List<User> list) {
        swRefresh.setRefreshing(false);
        adp.loadData(list);
        adp.notifyDataSetChanged();
    }


}
